package com.xdwanj.dao.impl;

import com.xdwanj.dao.BaseDao;
import com.xdwanj.dao.CategoryDao;
import com.xdwanj.pojo.Category;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class CategoryDaoImpl implements CategoryDao {
    private BaseDao baseDao = new BaseDao();
    JdbcTemplate jdbcTemplate = baseDao.getJdbcTemplate();

    @Override
    public List<Category> findCategory(int id) {
        StringBuffer sql = new StringBuffer("select * from category");
        if (id != 0) {
            sql.append(" where id = ?");
            return jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<Category>(Category.class), id);
        }
        return jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<Category>(Category.class));
    }
}
